import json
import os


class FileUtil:

    @staticmethod
    def create_txt(file_data, flag):
        try:
            current_path = os.path.dirname(os.path.abspath(__file__))
            root_path = os.path.dirname(current_path) + '/resource/config.json'
            with open(root_path, 'r') as f:
                config = json.load(f)
            if flag == 0:
                src = os.path.dirname(current_path) + config['cf']['file']
            else:
                src = os.path.dirname(current_path) + config['cf']['classfiy']
            if len(file_data) > 0:
                with open(src, 'w') as f:
                    for data in file_data:
                        f.write(data + '\n')
            return True
        except BaseException as e:
            print(f'生成文件异常：{e}')
            return False
